Skip to content

QtWS: Super Early Bird Tickets Available!

  • 0 Votes
    13 Posts
    2k Views
    C

    @KroMignon Hey! I forgot to answer to you! Did not meant to be rude and sorry for that :(
    Conclusion: I gave some tries with your suggest and lots of other stuff on internet, but failed :D
    So I have created a "Restart the system to apply all the language changes" screen and a "restart/cancel" choice on a language change state. I guess it will be okay even if it wont be "real-time" :P
    Good Work!

  • 0 Votes
    3 Posts
    555 Views
    C

    @KroMignon LOVE YOU!
    Thank you very much, worked w/out problems, and made me understand my mistake.
    note: Needed to update .ts file and release .qm file after changing code.

  • 0 Votes
    1 Posts
    362 Views
    No one has replied
  • 0 Votes
    11 Posts
    14k Views
    timdayT

    This got me thinking about how I structure things, which generally results from starting with a small one-file prototype and then breaking bits of it off into different files. Here's an example (all these can be run with qmlscene main.qml):

    First you might have

    File main.qml

    // main.qml import QtQuick 2.7 Rectangle { id: main width: 640 height: 480 property string msg0: "Some text" property string msg1: "Some more text" Column { anchors.centerIn: parent Text {text: main.msg0} Text {text: main.msg1} } }

    then you might try and organize stuff a bit:

    import QtQuick 2.7 Rectangle { id: main width: 640 height: 480 Item { id: config property string msg0: "Some text" property string msg1: "Some more text" } Column { anchors.centerIn: parent Text {text: config.msg0} Text {text: config.msg1} } }

    then you might split that up with a Config.qml:

    import QtQuick 2.7 Item { property string msg0: "Some text" property string msg1: "Some more text" }

    and main.qml now simplified to:

    import QtQuick 2.7 Rectangle { id: main width: 640 height: 480 Config {id: config} Column { anchors.centerIn: parent Text {text: config.msg0} Text {text: config.msg1} } }

    and then you start moving out other bits of functionality e.g adding a Messages.qml:

    import QtQuick 2.7 Column { anchors.centerIn: parent Text {text: config.msg0} Text {text: config.msg1} }

    and main.qml now simplified to:

    import QtQuick 2.7 Rectangle { id: main width: 640 height: 480 Config {id: config} Messages {} }

    I've never felt any need for singletons in QML code at all. (Having the hosting C++ set some context properties based on environment or command-line-options is the probably the closest I've come).

  • 0 Votes
    25 Posts
    11k Views
    p3c0P

    @Chillax You're Welcome :)